home *** CD-ROM | disk | FTP | other *** search
Korn shell script | 1995-03-24 | 796 b | 37 lines |
- #! /bin/ksh
- USAGE='USAGE: follow_link FILE_PATH
- If FILE_PATH is not a link, echo path, else, echo a path (relative or
- absolute) to the ultimate destination of the link).
- '
- # (C) Copyright 1995 by Michael Coulter. All rights reserved.
-
- # Process parameters
-
- if [ $# -ne 1 ]
- then
- echo "$USAGE" >&2
- exit 1
- fi
- FILE_PATH="$1"; shift
-
- # Do it
-
- if [ ! -L "$FILE_PATH" ]
- then
- echo "$FILE_PATH"
- exit 0
- fi
- LINK="$FILE_PATH"
- while [ -L "$LINK" ]
- do
- NEW_LINK="$(ls -l "$LINK" | cut -c56-500 | sed -e 's/^.* //')"
- if [ "$NEW_LINK" = "${NEW_LINK#/}" ]
- then
- # NEW_LINK is relative, add dirname of FILE_PATH
- DIR_PATH="$(dirname "$LINK")"
- NEW_LINK="$DIR_PATH/${NEW_LINK}"
- fi
- LINK="$NEW_LINK"
- done
- echo "$LINK"
-